//endcourse 已上课程样式
import React from 'react';
import MyOrderform from './myOrderform'
import http from '../../utils/http';
import Pager from '../components/Pager'
class MyOrder extends React.Component{
  state={
    pagers: {
      count: 5,
      index: 0,
      total: 0
    },
    orderList:[],
    haveorder:false

  }
// 修改orderList
  updateOrderList=(neworderList)=>{
     this.setState({orderList:neworderList})
  }

  getOrdercourse(){
    const pagers = this.state.pagers
    http
      .get('/order/myOrder', {
        params: {
          count: this.state.pagers.count,
          index: this.state.pagers.index
        }
      })
      .then(data=>{
        if(data.dataList.length===0){
          this.setState({
            haveorder:true
          })
          
        }else{
          pagers.total = data.count
          this.setState({
            orderList:data.dataList,
            pages: pagers,
            haveorder:false

          })
      }

      },err=>{
    })
  }

  changePage = (page) => {
    const pagers = this.state.pagers
    pagers.index = page
    this.setState({
      pagers
    })
    this.getOrdercourse()
  }
  //订单接口调取数据执行
  componentDidMount(){                    
    this.getOrdercourse();
  }

  render(){
      return (
        <div className="classed">
          <div style={{ fontFamily: 'PingFangSC-Regular',fontSize:18,color:'rgb(64,75,191)',borderBottom:"1px solid #404BBF",paddingBottom:10,marginLeft:15,marginRight:15}}>全部订单</div>
          {/* 订单的样式 */}
          
          {this.state.haveorder?<div style={{width:"100%",height:"100%",textAlign:"center",paddingTop:365,fontFamily: "PingFangSC-Regular",fontSize: 16,color: "#858585",letterSpacing: 0.21}}>您目前没有订单</div>:
            this.state.orderList.map((item,index)=>{
              return <MyOrderform dataText={item} key={item.orderId} changePage={this.changePage} pagers={this.state.pagers}/>
            })
          }
          <Pager pagers={this.state.pagers} changePage={this.changePage}></Pager>
        </div>
      )
  }
}

export default MyOrder